﻿using System;
using System.Windows.Forms;
using Microsoft.Office.Tools.Ribbon;
using eRechnung.Properties;


namespace eRechnung
{
    public partial class ebI_Ribbon : RibbonBase
    {

        public ebI_Ribbon()
            : base(Globals.Factory.GetRibbonFactory())
        {
            InitializeComponent();
        }

        private void ebI_Ribbon_Load(object sender, RibbonUIEventArgs e)
        {
            // SetRibbonButtonsEnable(false);
#if TEST_A_TRUST
            cbxTestRequ.Visible = true;
#else
            cbxTestRequ.Visible = false;
            cbxTestRequ.Enabled = false;
#endif
            if (Settings.Default.setHandyNr == "")
            {
                btnSignAndMail.Enabled = false; // wird erst freigegeben wenn Handy Einstellungen gespeichert wurden
            }
        }
        private void BtnDetails_Click(object sender, RibbonControlEventArgs e)
        {
            Form Details = new FrmDetails();
            Details.Show();

        }

        private void BtnSkonto_Click(object sender, RibbonControlEventArgs e)
        {

            Form myForm = new FrmSkonto();
            myForm.Show();
        }

        private void BtnSave_Click(object sender, RibbonControlEventArgs e)
        {
            eRechnung.Globals.ThisDocument.SaveXML(InvoiceXML.SaveMethodeTypes.AsUnsignedInvoice);
        }

        private void BtnEditSettings_Click(object sender, RibbonControlEventArgs e)
        {
            FrmEbInterfaceSettings ebIsetting = new FrmEbInterfaceSettings();
            ebIsetting.Show();
        }

        private void BtnSaveAsTemplate_Click(object sender, RibbonControlEventArgs e)
        {
            eRechnung.Globals.ThisDocument.SaveXML(InvoiceXML.SaveMethodeTypes.AsTemplate);
        }

        private void BtnLoadTemplate_Click(object sender, RibbonControlEventArgs e)
        {
            eRechnung.Globals.ThisDocument.LoadTemplateXML(InvoiceXML.TemplateTypes.FromFile);
        }

        private void BtnEbInterface_Click(object sender, RibbonControlEventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.ebinterface.at");
        }

        private void BtnAustriaPro_Click(object sender, RibbonControlEventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.austriapro.at");
        }

        private void BtnSignatur_Click(object sender, RibbonControlEventArgs e)
        {
            // http://portal.wko.at/wk/format_detail.wk?AngID=1&StID=424389&DstID=940
            System.Diagnostics.Process.Start("http://portal.wko.at/wk/format_detail.wk?AngID=1&StID=424389&DstID=940");
        }

        private void BtnAbout_Click(object sender, RibbonControlEventArgs e)
        {
            Form AboutForm = new AboutForm();
            DialogResult dr = AboutForm.ShowDialog();
        }

        private void BtnHelp_Click(object sender, RibbonControlEventArgs e)
        {
            MessageBox.Show("Weitere Hilfe finden Sie im mitgelieferten Dokument 'Ausfüllhilfe.pdf'.");
        }

        private void btnSignAndMail_Click(object sender, RibbonControlEventArgs e)
        {
#if TEST_A_TRUST
            if (cbxTestRequ.Checked == true)
            {
                eRechnung.Globals.ThisDocument.SaveXML(InvoiceXML.SaveMethodeTypes.SignAndMail2TestSystem);

            }
            else
            {
#endif
                eRechnung.Globals.ThisDocument.SaveXML(InvoiceXML.SaveMethodeTypes.SignAndMail2Production);
#if TEST_A_TRUST

            }
#endif
        }


        private void btnVerifySignature_Click(object sender, RibbonControlEventArgs e)
        {
            System.Diagnostics.Process.Start("https://pruefung.signatur.rtr.at/");
        }

        private void btnEinstellgSignatur_Click(object sender, RibbonControlEventArgs e)
        {
            FrmHandyEinstellungen HandyPrefs = new FrmHandyEinstellungen();
            HandyPrefs.ShowDialog();
        }

        private void btnNewInvoice_Click(object sender, RibbonControlEventArgs e)
        {
            DialogResult rc = MessageBox.Show("Sollen alle Datenfelder gelöscht werden und die Werte aus den Einstellungen neu übernommen werden?", "Daten löschen", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
            if (rc!=DialogResult.Yes)
            {
                return; 
            }
            eRechnung.Globals.ThisDocument.LoadTemplateXML(InvoiceXML.TemplateTypes.Empty);

        }
        /// <summary>
        /// Setzt bei den Ribbon Buttons die Eigenschaft Enabeled
        /// </summary>
        /// <param name="enable">true oder false</param>
        public void SetRibbonButtonsEnable(bool enable)
        {
            Globals.Ribbons.ebI_Ribbon.BtnSave.Enabled = enable;
            Globals.Ribbons.ebI_Ribbon.BtnSkonto.Enabled = enable;
            Globals.Ribbons.ebI_Ribbon.BtnDetails.Enabled = enable;
        }

        private void btnEinstellgFinOnl_Click(object sender, RibbonControlEventArgs e)
        {

            FrmFinOnlSettings FOsetting = new FrmFinOnlSettings();
            FOsetting.Show();

        }

        private void btnUIDBestaetigung_Click(object sender, RibbonControlEventArgs e)
        {
            eRechnung.Globals.ThisDocument.UID_Bestaetigung();
        }


    }
}
